package com.wagn.eduservice.controller;


import com.wagn.eduservice.entity.EduChapter;
import com.wagn.eduservice.entity.EduVideo;
import com.wagn.eduservice.entity.chapter.ChapterClassifyEntity;
import com.wagn.eduservice.entity.chapter.VoStep2AddChapter;
import com.wagn.eduservice.entity.chapter.VoStep2AddVideo;
import com.wagn.eduservice.service.EduChapterService;
import com.wagn.eduservice.service.EduVideoService;
import com.wagn.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-08-17
 */
@RestController
@CrossOrigin
@RequestMapping("/eduservice/chapter")
public class EduChapterController {

    @Autowired
    private EduChapterService eduChapterServicer;

    @Autowired
    private EduVideoService eduVideoService;

    @GetMapping("getChapterAndVideoById/{courseId}")
    public R getChapterAndVideoById(@PathVariable String courseId){
        ChapterClassifyEntity rs = eduChapterServicer.getChapterAndVideoById(courseId);
        return R.ok().data("rows",rs);
    }

    //删除Chapter
    @DeleteMapping("deleteChapter/{c}/{id}")
    public R deleteChapter(@PathVariable String c,@PathVariable String id){
        Boolean rs = eduChapterServicer.deleteChapter(c,id);
        return R.ok().data("rows",rs);
    }

    //修改Chapter
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter){
        boolean rs = eduChapterServicer.updateById(eduChapter);
        return R.ok().data("rows",rs);
    }

    //step2AddChapter添加Chapter
    @PostMapping("step2AddChapter")
    public R step2AddChapter(@RequestBody VoStep2AddChapter voStep2AddChapter){
        boolean rs = eduChapterServicer.step2AddChapter(voStep2AddChapter);
        return R.ok().data("rows",rs);
    }

    //step2AddVideo添加Video
    @PostMapping("step2AddVideo")
    public R step2AddVideo(@RequestBody VoStep2AddVideo voStep2AddVideo){
        boolean rs = eduChapterServicer.step2AddVideo(voStep2AddVideo);
        return R.ok().data("rows",rs);
    }
    //修改Video
    @PostMapping("updateVideo")
    public R updateVideo(@RequestBody EduVideo eduVideo){
        boolean rs = eduVideoService.updateById(eduVideo);
        return R.ok().data("rows",rs);
    }
}

